// components/menu/menu.js
//获取应用实例
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    userType: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    userInfo: {},
    hasUserInfo: false,
    animate: 'myfirst',
    yesorno: 'none',
    flag: true,
    test: 'test1',
    menuUrl: '',
    menuList: [{
      id: 0,
      name: '首 页',
      url: '../main/main'
    }, {
      id: 1,
      name: '我要推荐好友',
      url: '../recomFriend/recomFriend'
    }, {
      id: 2,
      name: '个人中心',
      url: '../my/my'
    }, {
      id: 3,
      name: '推荐奖励说明',
      url: '../reward/reward'
    }]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 跳转到相应的目录页
     */
    turnMenu(item) {
      let myEventDetail = item.currentTarget.dataset.url
      // 触发事件的选项
      const app = getApp()
      if (JSON.stringify(app.globalData.info) !== "{}") {
        //wx.navigateTo({
        /**
         * 2019-3-22
         * ch 修改
         * 关闭当前页跳转
        **/
        wx.navigateTo({
          url: myEventDetail,
        })
      } else {
        var myEventOption = {}
        this.triggerEvent('urlevent', myEventDetail, myEventOption)
      }
      this.laqi()
    },
    fabiao: function() {
      if (this.data.flag === true) {
        this.setData({
          yesorno: 'block'
        })
        this.setData({
          test: 'test1'
        })
        this.setData({
          flag: false
        })
      } else {
        this.setData({
          test: 'test2',
        })
        this.setData({
          flag: true
        })
      }
    },
    /**
     * 弹出框蒙层截断touchmove事件
     */
    preventTouchMove: function() {},
    /**
     * 收起菜单
     */
    laqi: function() {
      this.setData({
        test: 'test2',
      })
      this.setData({
        flag: true
      })
    }
  },
  /**
   * 组件挂载后执行
   */
  ready: function() {
    this.setData({
      userType: app.globalData.info.user_type
    })
    console.log('this.data.userType', this.data.userType, 'app.globalData.info.user_type', app.globalData.info.user_type)
  }
})
